package
{
	import com.hurlant.math.BigInteger;
	import com.hurlant.util.Base64;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.net.FileReference;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;
	
	import org.aswing.AsWingManager;
	import org.aswing.BoxLayout;
	import org.aswing.JFrame;
	import org.aswing.JPanel;
	import org.aswing.JWindow;
	
	import vno.fux.BasePoint;
	import vno.fux.ExPoint;
	import vno.fux.res.pool.BitmapAttacher;
	import vno.sci.Util;
	import vno.sci.event.MonologEvent;
	import vno.sci.mapEditor.*;
	import vno.sci.net.Login;
	import vno.sci.window.*;
	
	[SWF(frameRate="30")]
	public class SciMain extends Sprite
	{
		public var win:UILayer;
		public function SciMain()
		{
			//====Please reserve the following two lines below====
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			//=========================================
			var a:Object = {};
			a["title"] = "My aa";
			a["text"] = "";
			a["htmlText"] = "<i>italic</i><br/><b>BOLD</b>";
			a["titleHeight"] = 50;
			a["buttonHeight"] = 50;
			a["windowWidth"] = 400;
			a["windowHeight"] = 300;
			a["textWidth"] = 380;
			a["textHeight"] = 200;
			a["x"] = 0;
			a["y"] = 0;
			
			var b:Object = {};
			b["title"] = "My ee";
			b["text"] = "";
			b["htmlText"] = "<i>italic</i><br/><b>BOLD</b>";
			b["titleHeight"] = 50;
			b["buttonHeight"] = 50;
			b["windowWidth"] = 400;
			b["windowHeight"] = 300;
			b["textWidth"] = 380;
			b["textHeight"] = 200;
			b["x"] = 300;
			b["y"] = 300;
			
			
//			win = new UILayer();
			
//			win.newWindow(665,a,null,null);
		
//			win.addEventListener(MonologEvent.CLICK, func);
//			win.addEventListener(Event.RESIZE,onResize);//this will never happen.

			

//			this.addChild(win);
			//win.addEventListener(MonologEvent.NEXT, onNext);
			
		
//			var login:Login = new Login();
//			var a:ByteArray = new ByteArray();
//			var b:ByteArray = new ByteArray();
			
//			a.writeByte(1);
//			b.writeByte(2);
//			trace(a+b);
			
			//var test:BigInteger = new BigInteger("12");
			//trace(test.intValue());
			///trace(this.numChildren);
			///this.addChild(new SimpleMessageBox("sstnhsth", "euieui"));
			//trace(this.numChildren);
	
//			var mm:Minimap = new Minimap(200,null,new BasePoint(200,200));
//			this.addChild(mm);
//			var onClick:Function = function (e:MouseEvent):void
//			{
//				trace(e.localX, e.localY);
//			}
//			
//			mm.addEventListener(MouseEvent.CLICK,onClick);
//			
//			var test:ScrollMessageBox = new ScrollMessageBox("stnh",
//															 "sntheuooeuauoaoeuaoeuaoeusntha\noesuntahoseutnhaoseun\nhtaoseuhaosenuhas\noetnuhsano\nteuhsaonetuhsanoteuhasonetuhsanoteuhsanoetuhsaenotuhsaonteuhsantoeuhasotneuhsanoteuhsanoteuhasnoetuhsaonetuhsaoneuthaosnetuhsaoentuhsaoenuth",
//			                                                 300,0);
//			this.addChild(test);
			
//			var sss:MapMarker = new MapMarker();
//			this.addChild(sss);
			
//			var onC:Function = function (e:MouseEvent)
//			{	
//				test.setText("newnewnew");
//			}
//			
//			this.addEventListener(MouseEvent.CLICK,onC);
			
			
//			var aoeua:GlowMessageBox = new GlowMessageBox();
//			this.addChild(aoeua);
//			aoeua.addEventListener(MonologEvent.CLICK,function (e:MonologEvent):void{trace(e.id);});
			
			var m:MapEditor = new MapEditor(stage,20,20);
			
			
			
//				var o:OLabel = new OLabel("eu");
////				o.text = "stnh";
//				this.addChild(o);
								
				
				
				
				
				
				
				
//			var n:OPopup = new OPopup("stnhsntheo","Button1","Button2",null,null);
//			this.addChild(n);
			
			
			
			
			
			
					
		}
		public function doubleReverseString(string:String):String
		{
			var doubleReversed:String = new String();
			//string.length must be even;
			for (var i:int = 0; i < string.length; i+=2)
			{
				doubleReversed = string.slice(i,i+2).concat(doubleReversed);
			}
			return doubleReversed;
			
		}
		public function reverseString(string:String):String
		{
			var reversed:String = new String();
			for(var i:int = string.length -1; i >= 0; i--)
				reversed += string.charAt(i);
			return reversed;
		}
		
		public function byteArrayWriteHexString(ba:ByteArray, hex:String):void
		{
			for(var i:int = 0; i < hex.length; i+=2)
			{
				var hexStringToInt:BigInteger = new BigInteger(hex.slice(i+1,i+2)+hex.slice(i,i+1));
				ba.writeByte(hexStringToInt.intValue());
			}
		}
		
		protected function onNext(event:Event):void
		{
			// TODO Auto-generated method stub
			//test of functions
			trace(event);
			trace(this.numChildren);
		}
		
		private function onResize(event:Event):void
		{
			// TODO Auto-generated method stub
			trace("sth");
			win.alignCenter("My aa",stage.width,stage.height);
		}
	
	}
}